/**
 * 所有请求的地址
 */
layui.define(['jquery'], function (exports) {
    var $ = layui.jquery;
    var api = {
        LOGIN_URL: "/login",
        LOGOUT_URL: "/logout",
        BLOG_PUBLISH_URL: "/blog/publish",
        BLOG_DELETE_URL: "/blog/delete",
        LINK_SAVE_URL: "/assist/saveLink",
        TIMELINE_SAVE_URL: "/assist/saveTimeLine"

    };

    var action = {
        ajax: function (url, data, success, options, async) {
            options = options || {};
            data = data || {};
            return $.ajax({
                type: options.type || 'post',
                dataType: options.dataType || 'json',
                data: data,
                url: url,
                async: async || true,
                success: success || function () {
                    layer.msg("success回调函数不能为空");
                },
                error: function () {
                    options.error || layer.msg('请求异常，请重试', {
                        shift: 6
                    });
                }
            });
        },
        doAjax: function (url, data, success, options) {
            action.ajax(url, data, success, options, true);
        },

        login: function (params, success) {
            action.doAjax(api.LOGIN_URL, params, success);
        },
        logout: function (success) {
            action.doAjax(api.LOGOUT_URL, {}, success);
        },

        publishBlog: function (params, success) {
            action.doAjax(api.BLOG_PUBLISH_URL, params, success);
        },
        deleteBlog: function (params, success) {
            action.doAjax(api.BLOG_DELETE_URL, params, success);
        },

        saveLink: function (params, success) {
            action.doAjax(api.LINK_SAVE_URL, params, success);
        },

        saveTimeLine: function (params, success) {
            action.doAjax(api.TIMELINE_SAVE_URL, params, success);
        }
    };
    exports('api', action);
});